<div style="margin: 10px 0;"></div>
	<div id="kvConfigTreeSearchForm" style="padding:5px;height:auto">
	<div style="margin-bottom: 5px">
		<a href="#" onclick="openkvConfigTree()" class="easyui-linkbutton" iconCls="icon-add" plain="true">新增配置参数</a>
	</div>
	<div>
		<form id="queryKvConfigTreeForm">
			value值:<input class="easyui-validatebox" name="filter_S_value" style="width:100px">
			key:<input class="easyui-validatebox" name="filter_S_key" style="width:100px">
			<a href="javascript:doSearchObject('kvConfigTreeTable','queryKvConfigTreeForm')" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
		</form>
	</div>
</div>


<div id="add_kvConfigTree" class="easyui-window" title="配置信息管理" data-options="modal:true,closed:true,collapsible:false,minimizable:false,maximizable:false" style="width:450px; height: 300px; padding: 10px;">
	<div style="padding: 10px 0 10px 60px">
		<form id="adminKvConfigTreeForm" method="post" action="/kvConfigTree/save">
			<input name="id" value="0" type="hidden" id="_keyvaluetreeconfigid"/>
			<input name="parentId" value="0" type="hidden" id="_keyvaluetreeconfigparentid"/>
			<table>
				<tr>
					<td>Key值</td>
					<td><input type="text" autoComplete="off" name="key" class="easyui-validatebox" type="text" data-options="required:true" ></td>
				</tr>
				<tr>
					<td>Value值</td>
					<td><input type="text" autoComplete="off" name="value" class="easyui-validatebox" type="text" data-options="required:true"></td>
				</tr>
				<tr>
					<td>排序</td>
					<td>
						<input type="text" autoComplete="off" name="order" class="easyui-validatebox" type="text" data-options="required:true">
						值越小，越靠前
					</td>
				</tr>
				<tr>
					<td>描述</td>
					<td>
						<textarea name="desc" data-options="required:true" style="width:230px;height:50px;"></textarea>
					</td>
				</tr>
				<tr>
					<td>&nbsp;</td>
	            	<td>
	            		<input type="submit" value="提交"></input>
	            		<input type="reset" value="重置" ></input>
	           		</td>
				</tr>
			</table>
		</form>
	</div>
</div>


<table id="kvConfigTreeTable" class="easyui-datagrid" style="width:1050px"></table>

<script>

	$('#kvConfigTreeTable').treegrid({
		url:'/kvConfigTree/list?filter_S_orderByKey=order',
		idField: 'id',
		treeField: 'key',
		toolbar : '#kvConfigTreeSearchForm',
		rownumbers : true,
		columns : [[
			{field : 'key',title : 'Key值',width:200},
			{field : 'value',title : 'Value值',width:200},
			{field : 'order',title : '排序值',width:60},
			{field : 'desc',title : '描述',width:330},
			{field : 'operate',title : '操作',width:200,
				formatter : function(value, row, index) {
					if(row._parentId<=0){
						return outPutFunction("editConfigValuesTree",row.id,"编辑")+outPutFunction("freezeConfigValuesTree",row.id,"删除")+'[<a href="javascript:addChild('+row.id+')">新增子树</a>]';
					}else{
						return outPutFunction("editConfigValuesTree",row.id,"编辑")+outPutFunction("freezeConfigValuesTree",row.id,"删除");
					}	
				}
			} 
		]]
	});

	function addChild(oid){
		$("#adminKvConfigTreeForm").form('clear');
		$('#add_kvConfigTree').window('open');
		$("#_keyvaluetreeconfigparentid").val(oid);
		$("#_keyvaluetreeconfigid").val(0);
	}
	
	function openkvConfigTree(){
		$('#add_kvConfigTree').window('open');
		document.getElementById("adminKvConfigTreeForm").reset();
	}

	function editConfigValuesTree(cid) {
		jQuery.get("/kValuesConfig/getById?id="+cid, function(data) {
			$('#add_kvConfigTree').window('open');
			$("#adminKvConfigTreeForm").form('load',data);
		});
	}

	function freezeConfigValuesTree(cid) {
		jQuery.messager.confirm('配置信息管理',"确定要删除吗?",function(r){
			if(r){
				jQuery.post("/kValuesConfig/delete?id="+cid, function(data) {
					if (data == 1) {
						$("#kvConfigTreeTable").datagrid('reload');
					} else {
						jQuery.messager.alert('Info', "删除失败", 'info');
					}
				});
			}
		});
	}
	
	$('#adminKvConfigTreeForm').form({
		success : function(data) {
			if(data==-1) {
				jQuery.messager.alert('Info', "添加失败", 'info');
			}else{
				$('#add_kvConfigTree').window('close');
				$("#kvConfigTreeTable").treegrid('reload');
				$(".easyui-validatebox").val('');
		
			}
		}
	});
</script>

